/*
 * This file is part of SSHTTPD.
 *
 * SSHTTPD is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * SSHTTPD is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _SOCKET_H
#define _SOCKET_H
#define _GNU_SOURCE /* Using this for asprintf, id rather not but meh. */

/** @file
 * Defines global structures and functions implemented and used by socket.c.
 */

/* App level includes. */
#include "file.h"

/* System includes. */
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/types.h>
#include <arpa/inet.h>

/** 
 * Macro to send strings thru socket. 
 */
#define sendstr(u, s) send(u, s, strlen(s), 0)

/**
 * Asks the OS for a socket and sets it up to accept connections.
 * @param addr BSD socket structure. 
 * @param size Size of the socket structure.
 * @param port Port to listen on for connections. 
 * @return Socket descriptor on success, -Value on fail. 
 */
int init_socket(struct sockaddr_in *addr, int size, int port);

/** 
 * Reads data into the clients request buffer, keeps going untill CRCR
 * or RECBUFFMAX data is recieved.
 * @param ud Socket descriptor to read data from. (Clients descriptor)
 * @return Request string on success, NULL on fail. 
 */
char *readrequest(int ud);

#endif
